package com.controller;

import com.mapper.UserMapper;
import com.pojo.User1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class MybatisComtroller {

    @Autowired
     private UserMapper userMapper;

    @GetMapping("/allUser")
    public List<User1> queryAll(){
        List<User1> user1List = userMapper.queryAll();
        for (User1 user1 : user1List) {
            System.out.println(user1);
        }
        return  user1List;
    }
    @GetMapping("/oneUser/{id}")
    public User1 queryById(@PathVariable("id") int id){
        User1 user1 = userMapper.queryById(id);
        return user1;
    }
    @GetMapping("/addUser")
    public void addUser(){
        User1 user=new User1(10000,"刘备",2000d);
        userMapper.addUser(user);
    }
    @GetMapping("/udpUser")
    public void updataUser(){
        User1 user=new User1(10000,"张飞",100000d);
        userMapper.updataUser(user);
    }
    @GetMapping("/del/{id}")
    public void delUser(@PathVariable("id") int id){
        userMapper.delUser(id);
    }

}
